package cn.tedu.rabbitmqspring.m3;

import com.rabbitmq.client.Channel;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.support.AmqpHeaders;
import org.springframework.messaging.handler.annotation.Header;
import org.springframework.stereotype.Component;

/*
* 工作模式 多个消费者从同一个生产者接收消息
* */
@Component
public class Consumer {

    //启动一个消费者 从队列接受消息 并传递给这个方法进行处理
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue, //队列,不指定参数,由服务器自动命名,非持久,独占,自动删除
            exchange = @Exchange(name = "logs",declare="false") //交换机,declare="false"使用存在的交换机而不重复定义
    ))
    public void receive1(String s) throws Exception {
        System.out.println("receiver1 - 收到: "+s);



    }
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue, //队列,不指定参数,由服务器自动命名,非持久,独占,自动删除
            exchange = @Exchange(name = "logs",declare="false") //交换机,declare="false"使用存在的交换机而不重复定义
    ))
    public void receive2(String s) throws Exception {
        System.out.println("receiver2 - 收到: "+s);

    }

}
